package gpl.androidcommons.scotlandyard.adapter;

import gpl.androidcommons.R;
import gpl.androidcommons.scotlandyard.ui.SYColors;
import gpl.scotlandyard.beans.basics.Node;

import java.util.List;

import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NodeMapAdapter extends BaseAdapter {

  private final List<Node> map;
  private final LayoutInflater inflater;

  public NodeMapAdapter(List<Node> map, LayoutInflater inflater) {
    this.map = map;
    this.inflater = inflater;
  }

  @Override
  public int getCount() {
    return map.size();
  }

  @Override
  public Object getItem(int position) {
    return map.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View arg1, ViewGroup arg2) {
    TextView textView = (TextView) inflater.inflate(R.layout.text_view_rounded, null);
    GradientDrawable bgShape = (GradientDrawable) textView.getBackground();
    Node node = map.get(position);
    textView.setText(node.getNumber() + "");
    bgShape.setColor(SYColors.color4dNode(node).getRgbColor());
    return textView;
  }
}
